package com.weasel.http.adapter;

import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.Map;

/**
 * Created by Dylan on 2015/9/29.
 */
public abstract class TemplateReplaceResponseAdapter implements ResponseAdapter {


    @Override
    public String adapter(String responseBody) {

        Map<String,String> templates = getReplaceTemplate();
        int size = templates.keySet().size();
        String [] keys = templates.keySet().toArray(new String[size]);
        String [] values = templates.values().toArray(new String[size]);
        return StringUtils.replaceEach(responseBody,keys,values);
    }

    /**
     * @return
     */
    public abstract Map<String,String> getReplaceTemplate();

}
